home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Tool Chest / !Interfaces / Universal Interfaces 2.0a1 / CIncludes / Menus.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-17  |  11.8 KB  |  311 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        Menus.h
  3.  
  4.      Copyright:    © 1984-1994 by Apple Computer, Inc.
  5.                  All rights reserved.
  6.  
  7.      Version:    Universal Interfaces 2.0a1.  ETO #15, MPW prerelease.  Sunday, July 17, 1994. 
  8.  
  9.      Bugs?:        If you find a problem with this file, send the file and version
  10.                  information (from above) and the problem description to:
  11.  
  12.                      Internet:    apple.bugs@applelink.apple.com
  13.                      AppleLink:    APPLE.BUGS
  14.  
  15. */
  16.  
  17. #ifndef __MENUS__
  18. #define __MENUS__
  19.  
  20.  
  21. #ifndef __MEMORY__
  22. #include <Memory.h>
  23. #endif
  24. /*    #include <Types.h>                                            */
  25. /*        #include <ConditionalMacros.h>                            */
  26. /*    #include <MixedMode.h>                                        */
  27.  
  28. #ifndef __QUICKDRAW__
  29. #include <Quickdraw.h>
  30. #endif
  31. /*    #include <QuickdrawText.h>                                    */
  32.  
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36.  
  37. #if GENERATINGPOWERPC
  38. #pragma options align=mac68k
  39. #endif
  40.  
  41. #ifdef __CFM68K__
  42. #pragma lib_export on
  43. #endif
  44.  
  45.  
  46. enum {
  47.     noMark                        = 0,                            /*mark symbol for MarkItem*/
  48. /* menu defProc messages */
  49.     mDrawMsg                    = 0,
  50.     mChooseMsg                    = 1,
  51.     mSizeMsg                    = 2,
  52.     mDrawItemMsg                = 4,
  53.     mCalcItemMsg                = 5,
  54.     textMenuProc                = 0,
  55.     hMenuCmd                    = 27,                            /*itemCmd == 0x001B ==> hierarchical menu*/
  56.     hierMenu                    = -1,                            /*a hierarchical menu - for InsertMenu call*/
  57.     mPopUpMsg                    = 3,                            /*menu defProc messages - place yourself*/
  58.     mctAllItems                    = -98,                            /*search for all Items for the given ID*/
  59.     mctLastIDIndic                = -99                            /*last color table entry has this in ID field*/
  60. };
  61.  
  62. typedef struct MenuInfo MenuInfo, *MenuPtr, **MenuHandle;
  63.  
  64. struct MenuInfo {
  65.     short                            menuID;
  66.     short                            menuWidth;
  67.     short                            menuHeight;
  68.     Handle                            menuProc;
  69.     long                            enableFlags;
  70.     Str255                            menuData;
  71. };
  72. typedef pascal void (*MenuDefProcPtr)(short message, MenuHandle theMenu, Rect *menuRect, Point hitPt, short *whichItem);
  73. typedef pascal long (*MenuBarDefProcPtr)(short selector, short message, short parameter1, long parameter2);
  74. typedef pascal void (*MenuHookProcPtr)(void);
  75. typedef pascal short (*MBarHookProcPtr)(Rect *menuRect);
  76.  
  77. #if GENERATINGCFM
  78. typedef UniversalProcPtr MenuDefUPP;
  79. typedef UniversalProcPtr MenuBarDefUPP;
  80. typedef UniversalProcPtr MenuHookUPP;
  81. typedef UniversalProcPtr MBarHookUPP;
  82. #else
  83. typedef MenuDefProcPtr MenuDefUPP;
  84. typedef MenuBarDefProcPtr MenuBarDefUPP;
  85. typedef MenuHookProcPtr MenuHookUPP;
  86. typedef MBarHookProcPtr MBarHookUPP;
  87. #endif
  88.  
  89. enum {
  90.     uppMenuDefProcInfo = kPascalStackBased
  91.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(short)))
  92.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(MenuHandle)))
  93.          | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(Rect*)))
  94.          | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(Point)))
  95.          | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(short*))),
  96.     uppMenuBarDefProcInfo = kPascalStackBased
  97.          | RESULT_SIZE(SIZE_CODE(sizeof(long)))
  98.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(short)))
  99.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(short)))
  100.          | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(short)))
  101.          | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(long))),
  102.     uppMenuHookProcInfo = kPascalStackBased,
  103.     uppMBarHookProcInfo = SPECIAL_CASE_PROCINFO( kSpecialCaseMBarHook )
  104. };
  105.  
  106. #if GENERATINGCFM
  107. #define NewMenuDefProc(userRoutine)        \
  108.         (MenuDefUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppMenuDefProcInfo, GetCurrentArchitecture())
  109. #define NewMenuBarDefProc(userRoutine)        \
  110.         (MenuBarDefUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppMenuBarDefProcInfo, GetCurrentArchitecture())
  111. #define NewMenuHookProc(userRoutine)        \
  112.         (MenuHookUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppMenuHookProcInfo, GetCurrentArchitecture())
  113. #define NewMBarHookProc(userRoutine)        \
  114.         (MBarHookUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppMBarHookProcInfo, GetCurrentArchitecture())
  115. #else
  116. #define NewMenuDefProc(userRoutine)        \
  117.         ((MenuDefUPP) (userRoutine))
  118. #define NewMenuBarDefProc(userRoutine)        \
  119.         ((MenuBarDefUPP) (userRoutine))
  120. #define NewMenuHookProc(userRoutine)        \
  121.         ((MenuHookUPP) (userRoutine))
  122. #define NewMBarHookProc(userRoutine)        \
  123.         ((MBarHookUPP) (userRoutine))
  124. #endif
  125.  
  126. #if GENERATINGCFM
  127. #define CallMenuDefProc(userRoutine, message, theMenu, menuRect, hitPt, whichItem)        \
  128.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppMenuDefProcInfo, (message), (theMenu), (menuRect), (hitPt), (whichItem))
  129. #define CallMenuBarDefProc(userRoutine, selector, message, parameter1, parameter2)        \
  130.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppMenuBarDefProcInfo, (selector), (message), (parameter1), (parameter2))
  131. #define CallMenuHookProc(userRoutine)        \
  132.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppMenuHookProcInfo)
  133. #define CallMBarHookProc(userRoutine, menuRect)        \
  134.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppMBarHookProcInfo, (menuRect))
  135. #else
  136. #define CallMenuDefProc(userRoutine, message, theMenu, menuRect, hitPt, whichItem)        \
  137.         (*(userRoutine))((message), (theMenu), (menuRect), (hitPt), (whichItem))
  138. #define CallMenuBarDefProc(userRoutine, selector, message, parameter1, parameter2)        \
  139.         (*(userRoutine))((selector), (message), (parameter1), (parameter2))
  140. #define CallMenuHookProc(userRoutine)        \
  141.         (*(userRoutine))()
  142. /* (*MBarHookProcPtr) cannot be called from a high-level language without the Mixed Mode Manager */
  143. #endif
  144.  
  145. struct MCEntry {
  146.     short                            mctID;                        /*menu ID.  ID = 0 is the menu bar*/
  147.     short                            mctItem;                    /*menu Item. Item = 0 is a title*/
  148.     RGBColor                        mctRGB1;                    /*usage depends on ID and Item*/
  149.     RGBColor                        mctRGB2;                    /*usage depends on ID and Item*/
  150.     RGBColor                        mctRGB3;                    /*usage depends on ID and Item*/
  151.     RGBColor                        mctRGB4;                    /*usage depends on ID and Item*/
  152.     short                            mctReserved;                /*reserved for internal use*/
  153. };
  154. typedef struct MCEntry MCEntry;
  155.  
  156. typedef MCEntry *MCEntryPtr;
  157.  
  158. typedef MCEntry MCTable[1], *MCTablePtr, **MCTableHandle;
  159.  
  160. struct MenuCRsrc {
  161.     short                            numEntries;                    /*number of entries*/
  162.     MCTable                            mcEntryRecs;                /*ARRAY [1..numEntries] of MCEntry*/
  163. };
  164. typedef struct MenuCRsrc MenuCRsrc;
  165.  
  166. typedef MenuCRsrc *MenuCRsrcPtr, **MenuCRsrcHandle;
  167.  
  168. extern short GetMBarHeight( void )
  169.     TWOWORDINLINE( 0x3038, 0x0BAA ); /* MOVE.W $0BAA, D0 */
  170. extern pascal void InitMenus(void)
  171.  ONEWORDINLINE(0xA930);
  172. extern pascal MenuHandle NewMenu(short menuID, ConstStr255Param menuTitle)
  173.  ONEWORDINLINE(0xA931);
  174. extern pascal MenuHandle GetMenu(short resourceID)
  175.  ONEWORDINLINE(0xA9BF);
  176. extern pascal void DisposeMenu(MenuHandle theMenu)
  177.  ONEWORDINLINE(0xA932);
  178. extern pascal void AppendMenu(MenuHandle menu, ConstStr255Param data)
  179.  ONEWORDINLINE(0xA933);
  180. extern pascal void AppendResMenu(MenuHandle theMenu, ResType theType)
  181.  ONEWORDINLINE(0xA94D);
  182. extern pascal void InsertResMenu(MenuHandle theMenu, ResType theType, short afterItem)
  183.  ONEWORDINLINE(0xA951);
  184. extern pascal void InsertMenu(MenuHandle theMenu, short beforeID)
  185.  ONEWORDINLINE(0xA935);
  186. extern pascal void DrawMenuBar(void)
  187.  ONEWORDINLINE(0xA937);
  188. extern pascal void InvalMenuBar(void)
  189.  ONEWORDINLINE(0xA81D);
  190. extern pascal void DeleteMenu(short menuID)
  191.  ONEWORDINLINE(0xA936);
  192. extern pascal void ClearMenuBar(void)
  193.  ONEWORDINLINE(0xA934);
  194. extern pascal Handle GetNewMBar(short menuBarID)
  195.  ONEWORDINLINE(0xA9C0);
  196. extern pascal Handle GetMenuBar(void)
  197.  ONEWORDINLINE(0xA93B);
  198. extern pascal void SetMenuBar(Handle menuList)
  199.  ONEWORDINLINE(0xA93C);
  200. extern pascal void InsertMenuItem(MenuHandle theMenu, ConstStr255Param itemString, short afterItem)
  201.  ONEWORDINLINE(0xA826);
  202. extern pascal void DeleteMenuItem(MenuHandle theMenu, short item)
  203.  ONEWORDINLINE(0xA952);
  204. extern pascal long MenuKey(short ch)
  205.  ONEWORDINLINE(0xA93E);
  206. extern pascal void HiliteMenu(short menuID)
  207.  ONEWORDINLINE(0xA938);
  208. extern pascal void SetMenuItemText(MenuHandle theMenu, short item, ConstStr255Param itemString)
  209.  ONEWORDINLINE(0xA947);
  210. extern pascal void GetMenuItemText(MenuHandle theMenu, short item, Str255 itemString)
  211.  ONEWORDINLINE(0xA946);
  212. extern pascal void DisableItem(MenuHandle theMenu, short item)
  213.  ONEWORDINLINE(0xA93A);
  214. extern pascal void EnableItem(MenuHandle theMenu, short item)
  215.  ONEWORDINLINE(0xA939);
  216. extern pascal void CheckItem(MenuHandle theMenu, short item, Boolean checked)
  217.  ONEWORDINLINE(0xA945);
  218. extern pascal void SetItemMark(MenuHandle theMenu, short item, short markChar)
  219.  ONEWORDINLINE(0xA944);
  220. extern pascal void GetItemMark(MenuHandle theMenu, short item, short *markChar)
  221.  ONEWORDINLINE(0xA943);
  222. extern pascal void SetItemIcon(MenuHandle theMenu, short item, short iconIndex)
  223.  ONEWORDINLINE(0xA940);
  224. extern pascal void GetItemIcon(MenuHandle theMenu, short item, short *iconIndex)
  225.  ONEWORDINLINE(0xA93F);
  226. extern pascal void SetItemStyle(MenuHandle theMenu, short item, short chStyle)
  227.  ONEWORDINLINE(0xA942);
  228. extern pascal void GetItemStyle(MenuHandle theMenu, short item, unsigned char *chStyle);
  229. extern pascal void CalcMenuSize(MenuHandle theMenu)
  230.  ONEWORDINLINE(0xA948);
  231. extern pascal short CountMItems(MenuHandle theMenu)
  232.  ONEWORDINLINE(0xA950);
  233. extern pascal MenuHandle GetMenuHandle(short menuID)
  234.  ONEWORDINLINE(0xA949);
  235. extern pascal void FlashMenuBar(short menuID)
  236.  ONEWORDINLINE(0xA94C);
  237. extern pascal void SetMenuFlash(short count)
  238.  ONEWORDINLINE(0xA94A);
  239. extern pascal long MenuSelect(Point startPt)
  240.  ONEWORDINLINE(0xA93D);
  241. extern pascal void InitProcMenu(short resID)
  242.  ONEWORDINLINE(0xA808);
  243. extern pascal void GetItemCmd(MenuHandle theMenu, short item, short *cmdChar)
  244.  ONEWORDINLINE(0xA84E);
  245. extern pascal void SetItemCmd(MenuHandle theMenu, short item, short cmdChar)
  246.  ONEWORDINLINE(0xA84F);
  247. extern pascal long PopUpMenuSelect(MenuHandle menu, short top, short left, short popUpItem)
  248.  ONEWORDINLINE(0xA80B);
  249. extern pascal long MenuChoice(void)
  250.  ONEWORDINLINE(0xAA66);
  251. extern pascal void DeleteMCEntries(short menuID, short menuItem)
  252.  ONEWORDINLINE(0xAA60);
  253. extern pascal MCTableHandle GetMCInfo(void)
  254.  ONEWORDINLINE(0xAA61);
  255. extern pascal void SetMCInfo(MCTableHandle menuCTbl)
  256.  ONEWORDINLINE(0xAA62);
  257. extern pascal void DisposeMCInfo(MCTableHandle menuCTbl)
  258.  ONEWORDINLINE(0xAA63);
  259. extern pascal MCEntryPtr GetMCEntry(short menuID, short menuItem)
  260.  ONEWORDINLINE(0xAA64);
  261. extern pascal void SetMCEntries(short numEntries, MCTablePtr menuCEntries)
  262.  ONEWORDINLINE(0xAA65);
  263. extern pascal void InsertFontResMenu(MenuHandle theMenu, short afterItem, short scriptFilter)
  264.  THREEWORDINLINE(0x303C, 0x0400, 0xA825);
  265. extern pascal void InsertIntlResMenu(MenuHandle theMenu, ResType theType, short afterItem, short scriptFilter)
  266.  THREEWORDINLINE(0x303C, 0x0601, 0xA825);
  267. extern pascal Boolean SystemEdit(short editCmd)
  268.  ONEWORDINLINE(0xA9C2);
  269. extern pascal void SystemMenu(long menuResult)
  270.  ONEWORDINLINE(0xA9B5);
  271. #if CGLUESUPPORTED
  272. extern MenuHandle newmenu(short menuID, const char *menuTitle);
  273. extern void appendmenu(MenuHandle menu, const char *data);
  274. extern void insertmenuitem(MenuHandle theMenu, const char *itemString, short afterItem);
  275. extern long menuselect(const Point *startPt);
  276. extern void setmenuitemtext(MenuHandle menu, short item, const char *itemString);
  277. extern void getmenuitemtext(MenuHandle menu, short item, char *itemString);
  278. #endif
  279. #if OLDROUTINENAMES
  280. #define AddResMenu(theMenu, theType) AppendResMenu(theMenu, theType)
  281. #define InsMenuItem(theMenu, itemString, afterItem)  \
  282.     InsertMenuItem(theMenu, itemString, afterItem)
  283. #define DelMenuItem(theMenu, item) DeleteMenuItem(theMenu, item)
  284. #define SetItem(theMenu, item, itemString) SetMenuItemText(theMenu, item, itemString)
  285. #define GetItem(theMenu, item, itemString) GetMenuItemText(theMenu, item, itemString)
  286. #define GetMHandle(menuID) GetMenuHandle(menuID)
  287. #define DelMCEntries(menuID, menuItem) DeleteMCEntries(menuID, menuItem)
  288. #define DispMCInfo(menuCTbl) DisposeMCInfo(menuCTbl)
  289. #if CGLUESUPPORTED
  290. #define addresmenu(menu, data) appendresmenu(menu, data)
  291. #define getitem(menu, item, itemString) getmenuitemtext(menu, item, itemString)
  292. #define setitem(menu, item, itemString) setmenuitemtext(menu, item, itemString)
  293. #define insmenuitem(theMenu, itemString, afterItem)  \
  294.     insertmenuitem(theMenu, itemString, afterItem)
  295. #endif
  296. #endif
  297.  
  298. #ifdef __CFM68K__
  299. #pragma lib_export off
  300. #endif
  301.  
  302. #if GENERATINGPOWERPC
  303. #pragma options align=reset
  304. #endif
  305.  
  306. #ifdef __cplusplus
  307. }
  308. #endif
  309.  
  310. #endif /* __MENUS__ */
  311.